package org.example.cet.demos.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.po.User;
import org.example.cet.demos.domain.query.UserQuery;
import org.example.cet.demos.mapper.UserMapper;
import org.example.cet.demos.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@Service
@RequiredArgsConstructor

public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    public PageBean getPage(UserQuery userQuery) {
        Page<User> page = new Page<>(userQuery.getCurrentPage(), userQuery.getPageSize());
        lambdaQuery().like(User::getUsername, userQuery.getUsername())
//                .like(!StrUtil.isBlankIfStr(userQuery.getName()), User::getName, userQuery.getName())
                .like(!StrUtil.isBlankIfStr(userQuery.getGender()), User::getGender, userQuery.getGender())
                .like(!StrUtil.isBlankIfStr(userQuery.getRole()), User::getRole, userQuery.getRole())
                .like(!StrUtil.isBlankIfStr(userQuery.getTel()), User::getTel, userQuery.getTel())
                .page(page);
        PageBean pageBean = new PageBean();
        pageBean.setTotal(page.getTotal());
        pageBean.setRows(page.getRecords());
        return pageBean;
    }
}
